OpenRoads Designer CONNECT Edition SDK Help

Report missing text favorites in used Annotation group

The below code reports the missing text favorites from the annotation definitions of annotation groups.


//Required References
using Bentley.CifNET.ContentManagementModel;
using System.Collections.Generic;
using System.Diagnostics;

 public void ReportMissingTextFavouriteFromAG()
        {
            //Get object space
            Bentley.CifNET.CadSystem.IObjectSpaceManager objectSpaceManager = Bentley.CifNET.ServiceManager.Instance.GetService<Bentley.CifNET.CadSystem.IObjectSpaceManager>();
            if (objectSpaceManager == null) return;
            Bentley.CifNET.Objects.IObjectSpace objectSpace = objectSpaceManager.ObjectSpace;
            if (objectSpace == null) return;

            //Get ContentManagementModel
            Bentley.CifNET.ContentManagementModel.ContentManagementModel cmm = Bentley.CifNET.ContentManagementModel.ContentManagementModel.GetContentManagementModel(objectSpace, Bentley.CifNET.Model.GetModelOptions.CheckIfExist);
            if (cmm == null) return;

            //Get all annotation groups used in current DGN
            AnnotationGroupNameSet annotationGroupNameSet = cmm.AnnotationGroupNameSet;
            foreach (Bentley.CifNET.ContentManagementModel.AnnotationGroup annotationGroup in annotationGroupNameSet)
            {
                IEnumerable<Bentley.CifNET.ContentManagementModel.AnnotationDefinition> annotationDefinitions = annotationGroup.AnnotationDefinitions;
                foreach (Bentley.CifNET.ContentManagementModel.AnnotationDefinition annotationDefinition in annotationDefinitions)
                {
                    //Get annotation definition parameters
                    Bentley.ECObjects.Instance.IECInstance iECInstance = annotationDefinition.Parameters;
                    if (iECInstance == null) continue;

                    //Get text favorite value from parameters
                    Bentley.ECObjects.Instance.IECPropertyValue value = iECInstance.GetPropertyValue("Favorite");
                    if (value == null) continue;

                    string val = "";
                    bool status = value.TryGetStringValue(out val);

                    if (val == "")
                    {
                        Trace.WriteLine("Missing text favorite :" + "GroupName :" + annotationGroup.Name + "," + "AnnotationDefinition:" + annotationDefinition.Name);
                    }
                }
            }
        }

Output